
	
	
	
	
	
	
	
	function view_sj($id) {
		$data['po']	= $this->Po_model->get_list_data_detail($id);
        $this->load->view('admin_views/po/view_detail_sj', $data);
    }
	
	
	
	
	
	function detail($id){
		$profile = $this->Barang_model->selectDetail($id);
        	foreach($profile as $m)
			{
				$data['strnama']		= $m->strnama;
				$data['intharga_jawa']		= $m->intharga_jawa;
				$data['intpv_jawa']		= $m->intpv_jawa;
				$data['intharga_luarjawa']	= $m->intharga_luarjawa;
				$data['intpv_luarjawa']  	= $m->intpv_luarjawa;
				$data['strnama_jbarang']       	= $m->strnama_jbarang;
				$data['strnama_jsatuan']       	= $m->strnama_jsatuan;
                $data['qty']       	= $m->intqty;
            }

		$this->load->view('admin_views/barang/detail', $data);
	}
        
        function getno_nota(){
        $cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $week = $this->Po_model->selectWeek();
       // $month = $this->Po_model->selectMonth();
        $max = $this->Po_model->get_MaxNota()->result();
        $getnota = $this->Po_model->getNoNota($max[0]->intid_nota);
		if(empty($getnota[0]->intid_nota)){
			$nilai =1;
		} else {
			$nilai = $getnota[0]->intno_nota;
		}

        $noUrut = (int) substr($nilai, 5, 9);
        $noUrut++;
        //No/week/SJ/GudangName/bln/thn
        //SJ.2.25.00048
       $kode = "SJ.".sprintf("%05s", $noUrut).".".$week[0]->intid_week.".".$cabang[0]->intkode_cabang;
        //$kode = "$week[0]->intid_week.".$cabang[0]->strnama.".".SJ.".".sprintf("%05s", $noUrut);
        //".$cabang[0]->intkode_cabang.".
        return $kode;

    }
        //end if no nota

        //lookupcabang
     
        //
         //lookupBarang
    
       
		
	function delete($intid_po)
	{
		$this->Po_model->delete($intid_po);
		redirect('po/index');
	}

	function poAddPusat(){
		if (!$_POST)
		{

            $cabang = $this->User_model->getCabang($this->session->userdata('username'));
            $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);

            $data['cabang'] = $nm_cabang[0]->strnama_cabang;
            $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
			$data['week'] = $this->Penjualan_model->selectAllWeek();


            $data['user'] = $this->session->userdata('username');

			$this->load->view('admin_views/po/add2', $data);
		 }else{

            $ins = $this->Po_model->insert_pusat($_POST);

            //$max = $this->Po_model->get_MaxPo()->result();
            $id = $ins;
            $data = $this->input->post('barang');
            for($i=1;$i<=sizeof($data);$i++){
               // print_r($data[$i]);
            if(!empty($data[$i]['intid_id'])){
            $detail = array(
                            'intid_po' 		=> $id,
                            'intid_barang'	=> $data[$i]['intid_id'],
                            'intquantity'	=> $data[$i]['intquantity'],
							'ket'			=> $data[$i]['ket']
                            );

             $this->Po_model->add_pusat($detail);
            }
            }

			redirect('po/cetak_po_pusat');
		}

	}
	

	
	function cetak_po_pusat(){
        $max = $this->Po_model->get_MaxPoPusat()->row();
        $id = $max->intid_po;
        $ada = $this->Po_model->get_CetakPo_pusat($id);
        $data['default'] = $this->Po_model->get_CetakPo_pusat($id);
		$data['week'] = $this->Penjualan_model->selectWeek();
        $this->load->view('admin_views/po/cetak_po_pusat', $data);
	}
	
	

    function Retur(){
		if (!$_POST)
		{

            $cabang = $this->User_model->getCabang($this->session->userdata('username'));
            $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);

            $data['cabang'] = $nm_cabang[0]->strnama_cabang;
            $data['id_cabang'] = $nm_cabang[0]->intid_cabang;


            $data['user'] = $this->session->userdata('username');

			$this->load->view('admin_views/po/retur', $data);
		 }else{

            $this->Po_model->insertRetur($_POST);

           $max = $this->Po_model->get_MaxRetur()->result();
            $id = $max[0]->intid_retur;
            $data = $this->input->post('barang');
            for($i=1;$i<=sizeof($data);$i++){
            
            if(!empty($data[$i]['intid_id'])){
            $detail = array(
                            'intid_retur' 		=> $id,
                            'intid_barang'	=> $data[$i]['intid_id'],
                            'intquantity'	=> $data[$i]['intquantity']
                            );

             $this->Po_model->addRetur($detail);
            }
            }

			redirect('po/cetak_retur');
		}

	}

        function cetak_Retur(){
        $max = $this->Po_model->get_MaxRetur()->result();
        $id = $max[0]->intid_retur;
        $ada = $this->Po_model->get_CetakRetur($id);
        $data['default'] = $this->Po_model->get_CetakRetur($id);
        $this->load->view('admin_views/po/cetak_retur', $data);
	}
        
//Surat Jalan Cabang

function sjCab() {
        $data['form_action']	= site_url('po/sjCab');
        $var = "bulan";
        $terpilih = date('m');
        $bulan = 1;
        $b=12;
       $data['combo_bulan'] = $this->combonamabln($bulan, $b, $var, $terpilih);
        // Load data
        $data['bulan'] = "";
        $data['b'] = "";
        $data['cabang'] = "";

        if($_POST) {

            $data['po'] = $this->Po_model->get_all_sjCab($_POST);
            $data['bulan'] = $this->nama_bulan($this->input->post('bulan'));
            $data['b'] = $this->input->post('bulan');
        
            $data['cabang'] = $this->input->post('cabang');

            $ses = array(
			'bulan_session' => $this->input->post('bulan')
			
                        );
			$this->session->set_userdata($ses);

        }else {
            //$data['arisan'] = $this->Penjualan_model->get_all_arisan();
            $bulan_session = $this->session->userdata('bulan_session');
//
//            if(!empty($bulan_session)){
//                $po = $this->Po_model->get_all_po_session($bulan_session, $tahun_session, $group_session);
//                $data['po'] = $po;
//            }else{
//                $data['arisan'] = "";
//            }
        }
        $this->load->view('admin_views/po/sjCab', $data);
    }
     function combonamabln($awal, $akhir, $var, $terpilih) {
        $nama_bln=array(1=> "Januari", "Februari", "Maret", "April", "Mei",
                "Juni", "Juli", "Agustus", "September",
                "Oktober", "November", "Desember");
        $b='';
        $b.="<select name=$var id=$var>";
        for ($bln=$awal; $bln<=$akhir; $bln++) {
            if ($bln==$terpilih)
                $b.="<option value=$bln selected>$nama_bln[$bln]</option>";
            else
                $b.="<option value=$bln>$nama_bln[$bln]</option>";
        }
        $b.="</select> ";
        return $b;
    }

    function nama_bulan($bulan) {
        switch ($bulan) {
            case '1':
                $b = "Januari";
                break;
            case '2':
                $b = "Februari";
                break;
            case '3':
                $b = "Maret";
                break;
            case '4':
                $b = "April";
                break;
            case '5':
                $b = "Mei";
                break;
            case '6':
                $b = "Juni";
                break;
            case '7':
                $b = "Juli";
                break;
            case '8':
                $b = "Agustus";
                break;
            case '9':
                $b = "September";
                break;
            case '10':
                $b = "Oktober";
                break;
            case '11':
                $b = "November";
                break;
            case '12':
                $b = "Desember";
                break;

        }

        return $b;

    }

   

     function searchsj(){

		$this->Po_model->get_list_sj($_POST);
		redirect('admin_views/po/sj');
	}
     function searchData($intid_cabang, $intid_week)
	{
		if(($intid_cabang==NULL)&&($intid_week==NULL))
		{
			//$data['jumlah_data'] = "Data yang dicari tidak ditemukan dalam database!!!";
			$this->load->view('admin_views/po/sj',$data);
		}else {
			$data['po']=$this->Po_model->search($intid_cabang, $intid_week);
			$fields = $this->Po_model->search($intid_cabang, $intid_week);
			$data['jumlah_data']=count($fields);
			$this->load->view('admin_views/po/sj',$data);
		}

	}

 /*************************************Kartu Stok***********************************************/
    
 /*************************************End Of Kartu Stok*****************************************/
 /*************************************Lap Stok Cabang ******************************************/
/**************************************End of Lap Stok Cabang************************************/

	function view_po_pusat($id) {
		$data['po']	= $this->Po_model->get_list_data_detail_pusat($id);
        $this->load->view('admin_views/po/view_detail_po_pusat', $data);
    }
	
	function cetak_surat_jalan($kode){
		if(empty($kode)){
        $max = $this->Po_model->get_MaxSj()->result();
        $id = $max[0]->intid_sj;
		}else{
			$id = $kode;
			}
        $ada = $this->Po_model->get_cetak_surat_jalan($id);
        $data['default'] = $this->Po_model->get_cetak_surat_jalan($id);
		$data['week'] = $this->Penjualan_model->selectWeek();
        $this->load->view('admin_views/po/cetak_surat_jalan', $data);
	}

	
	
	
	
	
	
	
	
		
	
	
	
	

	
	
	function update_stat_brg() {
		$sj = $this->input->post('sj');
		for($i=0;$i<sizeof($sj);$i++) {
					if ($sj[$i] != ''):
							$where_ret['intid_detail_po'] = $sj[$i];
							$update_ret['status'] = 1;
							$intid_po = $this->Po_model->update_stat_brg($where_ret,$update_ret);
							//$con_value = $con_value - $get_retur_price->row()->price_retur;
					endif;
				}				
//		$po = $tis->input->post('intid_po');		
	//	echo $po
	}
	//opname
		

	function view_po_opname($id) {
		$data['no_po'] = $id;
		$data['po']	= $this->Po_model->get_list_data_detail($id);
        $this->load->view('admin_views/po/view_detail_po_opname', $data);
    }
	
		function update_fisik() {
		$sj = $this->input->post('detail_po');
		$fisik_pcs = $this->input->post('fisik_pcs');
		$fisik_set = $this->input->post('fisik_set');
		$no_po = $this->input->post('no_po');
		for($i=1;$i<=sizeof($sj);$i++) {
					if ($sj[$i] != ''):
							$where_ret['intid_detail_po'] = $sj[$i];
							$update_ret['fisik_pcs'] = $fisik_pcs[$i];
							$update_ret['fisik_set'] = $fisik_set[$i];
							
							$intid_po = $this->Po_model->update_stat_brg($where_ret,$update_ret);
							//$con_value = $con_value - $get_retur_price->row()->price_retur;
					endif;
				}		
			echo $no_po;			
//		$po = $tis->input->post('intid_po');		
	//	echo $po
	}

	function cetak_opname($id){
		$cab = $this->Po_model->get_Cabang_PO($id);
		
        $data['po'] = $this->Po_model->getLap_Stok_opname($id, $cab->intid_cabang);
		$data['week'] = $this->Penjualan_model->selectWeek();
		$data['opname'] = "coy";
        $this->load->view('admin_views/po/cetak_opname', $data);
	}